#include <stdio.h>
#include <string.h>
#include <math.h>

void p1() {
    char letter[26];
    char l = 'a';
    int i = 0;
    while (l <= 'z') {
        letter[i] = l;
        i++;
        l++;
    }
    for (int j = 0; j < 26; j++) {
        printf("%c|", letter[j]);
    }
    printf("\b\n");
}

void p2() {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j <= i; ++j) {
            printf("$");
        }
        printf("\n");
    }
}

void p3() {
    for (int i = 0; i < 6; ++i) {
        char f = 'F';
        for (int j = 0; j <= i; ++j, --f) {
            printf("%c", f);
        }
        printf("\n");
    }
}

void p4() {
    char l = 'A';
    for (int i = 0; i < 6; ++i) {
        for (int j = 0; j <= i; ++j, ++l) {
            printf("%c", l);
        }
        printf("\n");
    }
}

void p5() {
    char c;
    printf("Enter a upper char:");
    scanf("%c", &c);
    if (c >= 'A' && c <= 'Z') {
        for (char c1 = 'A'; c1 <= c; ++c1) {
            int space_size = c - c1;
            for (int i = 0; i < space_size; ++i) {
                printf(" ");
            }
            for (char c2 = 'A'; c2 <= c1; ++c2) {
                printf("%c", c2);
            }
            for (char c3 = c1 - 1; c3 >= 'A'; --c3) {
                printf("%c", c3);
            }
            printf("\n");
        }
    } else {
        printf("your enter a wong letter\n");
    }
}

void p6() {
    int start_number, end_number;
    printf("Enter start number:");
    scanf("%d", &start_number);
    printf("Enter end number:");
    scanf("%d", &end_number);
    printf("%8s%8s%8s\n", "number", "square", "cube");
    for (int i = start_number; i <= end_number; ++i) {
        printf("%8d%8d%8d\n", i, i * i, i * i * i);
    }
}

void p7() {
    char str[30];
    printf("Enter a word: ");
    scanf("%s", str);
    int length = strlen(str);
    for (int i = length - 1; i > -1; --i) {
        printf("%c", str[i]);
    }
    printf("\n");
}

float p8() {
    float f1, f2;
    float result = 0.0f;
    printf("enter two float:");
    if (scanf("%f%f", &f1, &f2) != 2) {
        printf("wong input\n");
        return result;
    }
    do {
        result = (f1 - f2) / (f1 * f2);
        printf("%f\n", result);
        printf("enter two float:");
    } while (scanf("%f%f", &f1, &f2) == 2);
    printf("wong input\n");
    return result;
}

float compute() {
    float f1, f2;
    float result = 0.0f;
    printf("enter two float:");
    if (scanf("%f%f", &f1, &f2) != 2) {
        printf("wong input\n");
        return result;
    }
    result = (f1 - f2) / (f1 * f2);
    return result;
}

void p9() {
    float r = compute();
    while (r > 0.0f || r < 0.0f) {
        r = compute();
    }
}

void p10() {
    int lower, upper, sc;
    printf("Enter lower and upper integer limits: ");
    sc = scanf("%d%d", &lower, &upper);
    while (sc == 2 && lower < upper) {
        int sq_lower = lower * lower;
        int sq_upper = upper * upper;
        int sum = 0;
        for (int i = lower; i <= upper; ++i) {
            sum += i * i;
        }
        printf("The sums of the squares from %d to %d is %d\n",
               sq_lower, sq_upper, sum);
        printf("Enter next set of limits: ");
        sc = scanf("%d%d", &lower, &upper);
    }
    printf("Done\n");
}

void p11() {
    int i8[8];
    printf("输入8个整数:");
    for (int i = 0; i < 8; ++i) {
        scanf("%d", &i8[i]);
    }
    for (int j = 7; j >= 0; --j) {
        printf("%d ", i8[j]);
    }
}

void p12() {
    int items, s;
    printf("Enter size of items: ");
    s = scanf("%d", &items);
    while (s == 1) {
        float sum1 = 0.0f, sum2 = 0.0f;
        for (int i = 0; i < items; ++i) {
            sum1 += 1.0f / (i + 1);
            float odd_even = (float) (pow(-1, i));
            sum2 += odd_even / (i + 1);
        }
        printf("sum1 = %f\n", sum1);
        printf("sum2 = %f\n", sum2);
        printf("Enter next size of items: ");
        s = scanf("%d", &items);
    }
    printf("done\n");
}

void p13() {
    int i8[8];
    for (int i = 1; i <= 8; ++i) {
        i8[i - 1] = 1 << i;
    }
    int i = 0;
    do {
        printf("%d ", i8[i]);
        i++;
    } while (i < 8);
    printf("done\n");
}

void p14() {
    int i8[8];
    int i8_2[8];
    printf("输入8个整数:");
    for (int i = 0; i < 8; ++i) {
        scanf("%d", &i8[i]);
        if (i == 0) {
            i8_2[i] = i8[i];
        } else {
            i8_2[i] = i8[i] + i8_2[i - 1];
        }
    }
    for (int j = 0; j < 8; ++j) {
        printf("%5d", i8[j]);
    }
    printf("\n");
    for (int j = 0; j < 8; ++j) {
        printf("%5d", i8_2[j]);
    }
    printf("\n");
}


void p15() {
    char string[256];
    printf("输入一行内容（小于255个字符）:");
    int i = 0;
    scanf("%c", &string[i]);
    for (; i < 255 && string[i] != '\n'; i++, scanf("%c", &string[i]));
    string[i + 1] = '\0';
    while (--i >= 0)
        printf("%c", string[i]);
}

void p16() {
    const float daphne_rate = .1f;
    float daphne = 100.0f;
    const float deirdre_rate = .05f;
    float deirdre = 100.0f;
    int years = 0;
    do {
        years++;
        daphne += 100.0f * daphne_rate;
        deirdre += deirdre * deirdre_rate;
    } while (daphne > deirdre);
    printf("spend %d years, deirdre having %f and daphne having %f\n",
           years, deirdre, daphne);
}

void p17() {
    int year = 1;
    float current_money = 100.0f;
    const float rate = .08f;
    while ((current_money += current_money * rate) > 10.0f) {
        year++;
        current_money -= 10.0f;
    }
    if (current_money > 0.0f) {
        year++;
    }
    printf("spend %d year , have no money", year);
}

void p18() {
    int current_friends = 5;
    int week;
    for (week = 0; current_friends <= 150;
            ++week, current_friends = (current_friends-week)*2);
    printf("week = %d", week);
}

int main() {
//    p1();
//    p2.c();
//    p3();
//    p4();
//    p5();
//    p6();
//    p7();
//    p8();
//    p9();
//    p10();
//    p11();
//    p12();
//    p13();
//    p14();
//    p15();
//    p16();
//    p17();
    p18();
    return 1;
}